﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace GenerateReports
{
    public partial class Util
    {
        public static List<Dictionary<string, string>> FindEntityPropertyAll(string ScorchXML)
        {

            List<Dictionary<string, string>> result = new List<Dictionary<string, string>>();
            var doc = XDocument.Parse(ScorchXML);
            var instances = from c in doc.Descendants()
                            where c.Name.LocalName == "properties"
                            select c.Descendants();

            foreach (var i in instances)
            {
                var ai = new Dictionary<string, string>();

                foreach (var e in i)
                {
                    ai.Add(e.Name.LocalName, e.Value);
                }

                result.Add(ai);
            }
            return result;
        }

        public static string FindPropertyValue(string ScorchXML, string PropertyName)
        {
            string result;
            var doc = XDocument.Parse(ScorchXML);
            result = (from e in doc.Descendants()
                      where e.Name.LocalName == PropertyName
                      select e.Value).First();

            return result;
        }

        public static List<string> FindPropertyValueCollection(string ScorchXML, string PropertyName)
        {
            List<string> result;
            var doc = XDocument.Parse(ScorchXML);
            result = (from e in doc.Descendants()
                      where e.Name.LocalName == PropertyName
                      select e.Value).ToList<string>();

            return result;
        }
    }
}
